﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;

namespace TinyRaytracer
{
    class Program
    {
        static void Main(string[] args)
        {
            FileStream strm, config;
            String source = "";
            try
            {
                strm = new FileStream (args[0], FileMode.Open, FileAccess.Read);
                StreamReader rdr = new StreamReader(strm);
                while (rdr.Peek() >= 0)
                {
                    string str = rdr.ReadLine();
                    source += str + "\n";
                }
                rdr.Close();

                config = new FileStream(args[1], FileMode.Open, FileAccess.Read);
                StreamReader cdr = new StreamReader(config);
                int part = Int32.Parse(cdr.ReadLine().Split(' ')[2]);
                int width = Int32.Parse(cdr.ReadLine().Split(' ')[2]);
                int height = Int32.Parse(cdr.ReadLine().Split(' ')[2]);
                int start_x = Int32.Parse(cdr.ReadLine().Split(' ')[2]);
                int start_y = Int32.Parse(cdr.ReadLine().Split(' ')[2]);
                int end_x = Int32.Parse(cdr.ReadLine().Split(' ')[2]);
                int end_y = Int32.Parse(cdr.ReadLine().Split(' ')[2]);
                cdr.Close();

                MainParsing mp = new MainParsing(width, height);
                mp.DoParse(source);
                mp.execute(start_x, start_y, end_x, end_y);
                mp.save("section" + part, start_x, start_y, end_x, end_y);
            }
            catch (Exception)
            {
                Console.WriteLine("Error opening file or no arguments received.");
            }
        }
    }
}
